package chap7.list;

import java.util.ArrayList;
import java.util.Collections;

public class ListExamples {
	
	public static void main(String[] args) {
		ListExamples listEx = new ListExamples();
		listEx.ArrayListExample();
	}
	
	/**
	 *  1. It can grow dynamically
	 *  2. Provides more dynamic insertion & search mechanism
	 *  3. Ordered by index
	 *  4. not sorted
	 *  5. Implements RandomAccess Interface - a marker interface
	 *  6. Faster iteration & random access
	 *  7. collections can hold OBJECTS but NOT PRIMITIVES
	 *     hence PRIMITIVES need to be wrapped which is taken care by AUTOBOXING     
	 */
	public void ArrayListExample(){
		ArrayList< String> arrayList = new ArrayList<String>();
		arrayList.add("Amit");
		arrayList.add("Vinod");
		arrayList.add("Matt");
		arrayList.add("Michel");
		System.out.println(arrayList);
		arrayList = sortingArrayList(arrayList);
		System.out.println(arrayList);
		
		Car c = new Car(4,"blue","abc");
		Car c1 = new Car(1,"black","xyz");
		
		ArrayList<Car> arrayListOfCar = new ArrayList<Car>();
		arrayListOfCar.add(c);
		arrayListOfCar.add(c1);
		System.out.println("------------------");
		for (Car car : arrayListOfCar) {			
			System.out.println(car.carNo);
		}
		System.out.println("------------------");
		Collections.sort(arrayListOfCar);
		for (Car car : arrayListOfCar) {			
			System.out.println(car.carNo);
		}
		System.out.println("------------------");
		Car cc = new Car();
		Collections.sort(arrayListOfCar, cc);
		
		for (Car car : arrayListOfCar) {			
			System.out.println(car.carNo);
		}
	}
	
	public ArrayList<String> sortingArrayList(ArrayList<String> arr){
		Collections.sort(arr);
		return arr;
	}
	
	public int comparetoMethod(Car car){
		
		return 0;		
	}

}
